package com.victor.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.victor.dao.BannerDao;
import com.victor.entity.Banner;
import com.victor.service.BannerService;
import com.victor.utils.redis.RedisTool;

@Service
public class BannerServiceImpl implements BannerService {

	@Autowired
	private BannerDao dao;

	@Autowired
	private RedisTool redisTool;

	@Override
	public boolean insert(Banner banner) {

		return dao.insert(banner) > 0 ? true : false;
	}

	public boolean update(Banner banner) {
		return dao.update(banner);
	}

	@Override
	public boolean batchDelete(int[] ids) {
		return dao.batchDelete(ids) > 0 ? true : false;
	}

	@Override
	public List<Banner> selectAll() {
		List<Banner> banners = (List<Banner>) redisTool.get("banners");
		if (null == banners) {
			banners = dao.selectAll();
			redisTool.set("banners", banners);
		}
		return banners;
	}

	@Override
	public List<Banner> selecByPara(Banner banner) {
		return dao.selecByPara(banner);
	}

}
